import { Component,Input,OnInit,OnChanges,OnDestroy } from '@angular/core';

import { AttrSellService } from './attr.sell.service';

import { Util } from '../../../utils/util';

@Component({
	selector: 'attr-sell',
	templateUrl: './attr.sell.html',
	providers: [AttrSellService]
})

export class AttrSellComponent {

	@Input('poolData') poolData:any;


	curProp:any = {};


	vm = {
    "loading": true,
    "data": [],
    "column": {
      fileName: '',
      dim: ['date', 'combProperty', 'brandName', 'sellMoney', 'sellAmount', 'monthSellMoney', 'monthSellAmount', 'productNum', 'shopNum', 'tsellMoney', 'tsellAmount', 'monthTSellMoney', 'monthTSellAmount', 'tproductNum', 'tshopNum', 'thksellMoney', 'thksellAmount', 'monthThkSellMoney', 'monthThkSellAmount', 'thkproductNum', 'thkshopNum', 'gsellMoney', 'gsellAmount', 'monthGSellMoney', 'monthGSellAmount', 'gproductNum', 'gshopNum', 'csellMoney', 'csellAmount', 'monthCSellMoney', 'monthCSellAmount', 'cproductNum', 'cshopNum'],
      dimText: ['时间', '类目id', '品牌名', '日销售额', '日销售量', '近30天销售额', '近30天销售量', '动销宝贝数', '动销店铺数', '天猫日销售额', '天猫日销售量', '天猫近30天销售额', '天猫近30天销售量', '天猫宝贝数', '天猫店铺数', '天猫国际日销售额', '天猫国际日销售量', '天猫国际近30天销售额', '天猫国际近30天销售量', '天猫国际宝贝数', '天猫国际店铺数', '全球购日销售额', '全球购日销售量', '全球购近30天销售额', '全球购近30天销售量', '全球购宝贝数', '全球购店铺数', '淘宝日销售额', '淘宝日销售量', '淘宝近30天销售额', '淘宝近30天销售量', '淘宝宝贝数', '淘宝店铺数']
    },
    "type": 'line-mm'
  };

  columns = ['时间', '日销售量', '日销售额', '近30天销售量', '近30天销售额', '动销店铺数', '动销宝贝数'];

	constructor(private service: AttrSellService,private util :Util) { }

	ngOnChanges(changes){
		console.log(changes);
	}



	export(){
		let data = this.util.jsonToArrry(this.vm.data, this.vm.column.dim, this.vm.column.dimText);

    this.util.export(data, this.vm.column.fileName);
	}

	xhrBusy:any;
	getHttp(){

		if(this.vm.loading && this.xhrBusy){
			this.xhrBusy.unsubscribe();
		}

		let json = {
			categoryId:'',
			property:''
		};

		this.vm.data.length = 0;

		this.curProp = {};

		this.xhrBusy = this.service.get(json).subscribe((res:any)=>{

			let length = res.data.length;

			if(length > 0){
				this.vm.data = res.data;

				this.curProp = res.data[length-1];
			}

			this.vm.loading = false;

		});
	}


}